//index.js
const app = getApp()
const Api = require("../../../utils/api.js").API
const Store = require("../../../utils/store.js").store
const codeZ = require("../../../utils/util.js")
const citys = {
  今天: ['2', '宁波', '温州', '嘉兴', '湖州'],
  明天: ['福州', '厦门', '莆田', '三明', '泉州'],
};


Component({
   properties:{
     goods:Object,
     statusZhi:String,
     paymentMethod:String,
     payStatus:String,
     coupon:Object,
     actualTotalAmt:Number,
     totalAmt:Number,
     batchNo:String
     
     
   },
  data: {
      
        showMore:false,
      
      
  }, 
  ready(){
      
    //   var a = this.properties.orderlist;
    
    //  this.setData({
    //      goods:a,   
    //  })
   },
  methods: { 
      listToggle: function () {
        this.setData({
          showMore: !this.data.showMore
        })
      },
      
      cancel:function(e){
         
          let that = this;
          var zhi = that.properties.statusZhi;
         var a = e.currentTarget.dataset.item;
           var data = {'coOrderNo':a.ckOrderNo};
           Api.cancelOrderApi(data).then(res=>{
            
               if(res.code != 0){                              
                  wx.showToast({
                    title: res.msg,
                    icon: 'none',
                    duration: 3000,
                    })

               }else{
                   that.triggerEvent('backType', {
                              zhi
                    }, {});
               }
               
                
               
           })
      },
     
      clickDetail:function(e){
             var a = e.currentTarget.dataset.item;
             var goods = this.data.goods;
           wx.navigateTo({
               url: "../OfflinePayment/index?type='1'",
               success: function(res) {
                 // 通过eventChannel向被打开页面传送数据
                 res.eventChannel.emit('acceptGoods', { goods:goods })
               }
           })  
      },
      suresh:function(e){
          let that = this;
           var zhi = that.properties.statusZhi;
          var a = e.currentTarget.dataset.item;
            var data = {'ckOrderNo':a};
      Api.confirm_receiptApi(data).then(res=>{
            
               if(res.code != 0){                              
                  wx.showToast({
                    title: res.msg,
                    icon: 'none',
                    duration: 3000,
                    })
      
               }else{
                   that.triggerEvent('backType', {
                              zhi
                    }, {});
               }
               
                
               
           })
      },
           
      cancelAll:function(e){
       
          let that = this;
           var zhi = that.properties.statusZhi;
         let data= this.properties.batchNo;      
         var params = {
            
             "batchOrderNo":data
         }
           Api.batch_cancelApi(params).then(res=>{
            
               if(res.code != 0){                              
                  wx.showToast({
                    title: res.msg,
                    icon: 'none',
                    duration: 3000,
                    })
      
               }else{
                   that.triggerEvent('backType', {
                              zhi
                    }, {});
               }
               
                
               
           })
      },
      // suresh:function(e){
          
      // }
           
    
     
     quFu: function(e) {
         // console.log(e);
         let that =this;
         let data= this.properties.batchNo;
          
       
         var params = {
            
             "batchOrderNo":data
         }
         wx.showLoading({
             title: '...',
             mask: true
         })
         Api.getOrdeApi(params).then(resp => {
             wx.hideLoading()
            
             if (resp.code == 0) {
                 wx.showToast({
                     title: '下单成功',
                      icon: 'none'
                 })
                 
               
              
                 that.wxPay(resp.data.weChatAppletOrder)
                 
             } else {
                 wx.showToast({
                     icon: 'none',
                     title: resp.msg
                 })
             }
         })              
     },
    
    wxPay: function(weChatAppletOrde) {
         var that = this;
         console.log(weChatAppletOrde)
         wx.requestPayment({
             timeStamp: weChatAppletOrde.timeStamp,
             nonceStr: weChatAppletOrde.nonceStr,
             package: weChatAppletOrde.pay_package,
             signType: weChatAppletOrde.signType,
             paySign: weChatAppletOrde.paySign,
             success: function(res) {
                  that.cheakCart()
                 wx.showToast({
                     title: '支付成功'
                 })
                 wx.navigateTo({
                     url: '../order/index',
                 })
             }
         })
     },
           
           huanhuo:function(e){
               let that = this
                 var a = e.currentTarget.dataset.item;
                  var zhi = that.properties.statusZhi;
        
               Api.orderTranApi({'orderNo':a.orderNo}).then(res=>{
                   if(res.code == 0){
                       that.triggerEvent('backType', {
                                  zhi
                        }, {});
                       
                   }
                  
               })
               
           },
           
           fapiao:function(){ 
               
              let batchNo= this.properties.batchNo; 
               let coupon= this.properties.coupon.useCouponVal; 
                let totalAmt= this.properties.totalAmt; 
             var aa = ((totalAmt * 10 * 10 - coupon * 10*10) / 100).toFixed(2);
              var str ={
                  'a':batchNo,
                  'b':aa
                  
              }
                 
                  wx.navigateTo({
                           url: '../FaPiao/index',
                             success: function(res) {
                               // 通过eventChannel向被打开页面传送数据
                               res.eventChannel.emit('acceptDataFromOpenerPage', { data:str })
                             }
                     })
              
              
         
           }
  },
  
  
  

})
